class RoleTest extends grails.util.WebTest {
    // Unlike unit tests, functional tests are often sequence dependent.
    // Specify that sequence here.
    void suite() {
        testRoleListNew()
        // add tests for more operations here
    }
    def testRoleListNew() {
        webtest('Role basic operations: view list, create new entry, view, edit, delete, view') {
            invoke      'role'
            verifyText  'Home'

            verifyListSize 0

            clickLink   'New Role'
            verifyText  'Create Role'
	    // Set input field
	    setInputField(name:'name', 'Organiser')
            clickButton 'Create'
            verifyText  'Show Role', description:'Detail page'
            clickLink   'List', description:'Back to list view'

            verifyListSize 1

            group(description:'edit the one element') {
                showFirstElementDetails()
                clickButton 'Edit'
                verifyText  'Edit Role'
                clickButton 'Update'
                verifyText  'Show Role'
                clickLink   'List', description:'Back to list view'
            }
            verifyListSize 1
        }
    }
    String ROW_COUNT_XPATH = "count(//div[@class='list']//tbody/tr)"

    def verifyListSize(int size) {
        ant.group(description:"verify Role list view with $size row(s)") {
            verifyText  'Role List'
            verifyXPath xpath:      ROW_COUNT_XPATH,
                        text:       size,
                        description:"$size row(s) of data expected"
        }
    }
    def showFirstElementDetails() {
        ant.clickLink   '1', description:'go to detail view'
    }
    def delete() {
            group(description:'delete the only element') {
                showFirstElementDetails()
                clickButton 'Delete'
            }
            verifyListSize 0
    }
}
